<include file="/public/header" />
<script type="text/javascript">
    window._AMapSecurityConfig = {
        securityJsCode: '7156d1a798a03528b14cd669b194413b',
    }
</script>
<script
    src="https://webapi.amap.com/maps?v=2.0&key=81fed9345d752098eb43bfbacea4b2bf&plugin=AMap.AutoComplete,AMap.PlaceSearch">
    </script>
<style>
    .layui-card-body {
        padding-left: 0;
    }

    .layui-form-item .layui-input-inline {
        width: 220px;
    }
</style>

<div class="layui-fluid layui-bg-white">
    <form class="layui-form layui-form-fixed">
        <gt name="$data.id" value="0"><input type="text" name="id" value="{$data.id}" hidden=""></gt>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('订单ID')}</label>
            <div class="layui-input-block">
                <input style="border: none;" value="{$data.id}" disabled class="layui-input" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('订单类型')}</label>
            <div class="layui-input-block">
                <select name="type">
                    <option disabled value="1" <if $data.type==1>selected</if>>下单</option>
                    <option disabled value="2" <if $data.type==2>selected</if>>退单</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('订单状态')}</label>
            <div class="layui-input-block">
                <input style="border: none;" value="{$data.status_text}" disabled class="layui-input"
                    lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('修改状态')}</label>
            <div class="layui-input-block">
                <select name="getstatus">
                    <option value="">{:__('修改状态')}</option>
                    <foreach name="statusArr" item="v" key="k">
                        <if $k gt 1>
                            <option value="{$k}">{$v}</option>
                        </if>
                    </foreach>
                </select>
            </div>
            <div class="layui-input-block">注:未确认订单变更为取消外其他状态会变更库存，已确认订单变更取消状态会影响库存</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('下单员')}</label>
            <div class="layui-input-block">
                <select name="user_id">
                    <option value="">{:__('选择下单员')}</option>
                    <foreach $user2 as $v>
                        <option value="{$v.id}" <if $data.user_id==$v.id>selected</if>>{$v.name}</option>
                    </foreach>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('客户姓名')}</label>
            <div class="layui-input-block">
                <input name="name" value="{$data.name}" placeholder="{:__('客户姓名')}" type="text" class="layui-input"
                    lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('客户电话')}</label>
            <div class="layui-input-block">
                <input name="mobile" value="{$data.mobile}" placeholder="{:__('客户电话')}" type="text" class="layui-input"
                    lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('定位地址')}</label>
            <div class="layui-input-block">
                <input name="latlon" type="hidden" class="layui-input" value="{$data.latlon}" />
                <input name="readdress" z-index="999999999999" id="tipinput" placeholder="{:__('请输入定位地址')}" type="text"
                    class="layui-input" lay-verify="required" value="{$data.readdress}" />
                <div id="sousuo"
                    style="position:absolute;z-index:999999;background:#fff;padding:5px;border:1px solid #dedede">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('详细地址')}</label>
            <div class="layui-input-block">
                <input name="address" value="{$data.address}" placeholder="{:__('详细地址')}" type="text"
                    class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('送达时间')}</label>
            <div class="layui-input-block">
                <input name="yjsd" value="{$data.yjsd}" lay-datetime="" data-datetype="datetime"
                    data-dateformat="yyyy-MM-dd HH:mm" placeholder="{:__('配送时间')}" type="text" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('配送方式')}</label>
            <div class="layui-input-block">
                <input type="radio" name="send_type" lay-filter="send_type" value="1" title="公司配送" <if
                    $data.send_type==1>checked</if>>
                <input type="radio" name="send_type" lay-filter="send_type" value="2" title="自提" <if
                    $data.send_type==2>checked</if>>
                <input type="radio" name="send_type" lay-filter="send_type" value="3" title="货拉拉" <if
                    $data.send_type==3>checked</if>>
                <input type="radio" name="send_type" lay-filter="send_type" value="4" title="挂车" <if
                    $data.send_type==4>checked</if>>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('配送员')}</label>
            <div class="layui-input-block">
                <div id="selectids" <if $data.send_type gt 1> style="display: none;"</if>>
                    <select name="ouser_id">
                        <option value="">{:__('选择配送员')}</option>
                        <foreach $user1 as $v>
                            <option value="{$v.id}" <if $data.ouser_id==$v.id>selected</if>>{$v.name}</option>
                        </foreach>
                    </select>
                </div>
                <div id="selectoids" <if $data.send_type elt 1> style="display: none;"</if>>
                    <input name="send_mobile" value="{$data.send_mobile}" placeholder="{:__('配送联系电话')}" type="text"
                        class="layui-input" />
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:__('备注')}</label>
            <div class="layui-input-block">
                <input name="remark" value="{$data.remark}" placeholder="{:__('备注')}" type="text" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">送达图片</label>
            <div class="layui-input-block">
                <div class="layui-imagesbox">
                    <notempty name="$data['images']">
                        <volist name="$data['images']" id="vo">
                            <div class="layui-input-inline layui-uplpad-image">
                                <img src="{$vo.url}" lay-image-hover>
                                <input type="text" name="album[{$key}][src]" hidden value="{$vo.url}">
                                <span class="layui-badge layui-badge-red"
                                    onclick="layui.$(this).parent().remove();">删除</span>
                            </div>
                        </volist>
                    </notempty>
                    <div class="layui-input-inline layui-uplpad-image">
                        <div class="layui-upload-drag" lay-upload="album" data-type="multiple" data-accept="images"
                            data-size="102400">
                            <i class="layui-icon layui-icon-upload"></i>
                            <p>点击上传，或将文件拖拽到此处</p>
                            <div class="layui-hide"></div>
                        </div>
                        <input class="layui-upload-file" type="file" accept="" name="file">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-footer layui-form-item layui-center ">
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closeDialog">取消</button>
            <button class="layui-btn layui-btn-normal" lay-filter="submitIframe" type="button" lay-submit>提交</button>
        </div>
    </form>
</div>
<include file="/public/footer" />
<include file="/public/static" />
<script>
    layui.use(['admin', 'table', 'form'], function () {
        var admin = layui.admin;
        var table = layui.table;
        var form = layui.form;
        //监听地址选择
        form.on('radio(send_type)', function (data) {
            if (data.value <= 1) {
                layui.$('#selectids').show();
                layui.$('#selectoids').hide();
            } else {
                layui.$('#selectids').hide();
                layui.$('#selectoids').show();
            }
        });
        //默认隐藏地址信息
        layui.$('#sousuo').hide();
        //点击元素外其它地方隐藏
        layui.$('body').bind('click', function (event) {
            layui.$('#sousuo').hide();
        });
        //阻止冒泡
        layui.$('#sousuo').click(
            function (e) {
                e.stopPropagation()
            }
        );
        //输入框的值改变时触发
        layui.$("#tipinput").on("input", function (e) {
            //获取input输入的值
            layui.$.get("{:url('/ajax/getaddress')}",
                { keyword: e.delegateTarget.value }, function (res) {
                    if (res.code == 200) {
                        str = '';
                        layui.$.each(res.data, function (i, obj) {
                            str += '<input lay-filter="getsou" type="radio" name="suosuo" value="' + obj.location + '" title="' + obj.name + '[' + obj.address + ']' + '"><br/>';
                        });
                        layui.$('#sousuo').html(str);
                        layui.$('#sousuo').show();
                        form.render();
                    } else {
                        layui.$('#sousuo').html();
                        layui.$('#sousuo').hide();
                        form.render();
                    }

                }, 'json');
        });
        //监听地址选择
        form.on('radio(getsou)', function (data) {
            console.log(data.othis);
            var location = data.value.split(","); //字符分割 
            if (location.length >= 2) {
                layui.$('#sousuo').hide();
                layui.$("input[name='latlon']").val(data.value);
                layui.$("input[name='readdress']").val(data.othis[0]['innerText'].substring(1));
            } else {
                layer.msg('数据错误，请重试');
            }

        });
    })
</script>